<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta content="text/html;charset=utf-8"></meta>
    <title>商户列表</title>
    <link rel="stylesheet" href="/static/js/common/bootstrap/css/bootstrap.min.css"></link>
    <link rel="stylesheet" href="/static/css/base.css"></link>
    <link rel="stylesheet" href="/static/js/common/layer/theme/default/layer.css"></link>
    <script src="/static/js/common/jquery/jquery-3.2.1.min.js"></script>
    <script src="/static/js/common/layer/layer.js"></script>
    <script src="/static/js/base/base.js"></script>
    <script>
        //删除记录
        function deleteRecord(data) {

            // var idStr = "#busAddress";
            // var busAddr = $("#busAddress");
            // // layer.msg(busAddr.attr("class"));
            // var busAddr2 = $(idStr);
            // layer.msg(busAddr2.attr("class"));


            // layer.confirm('您是如何看待前端开发？', {
            //     btn: ['重要','奇葩'] //按钮
            // }, function(){
            //     layer.msg('的确很重要', {icon: 1});
            // }, function(){
            //     layer.msg('也可以这样', {
            //         time: 20000, //20s后自动关闭
            //         // btn: ['明白了', '知道了']
            //     }, function(){
            //         alert("明白了");
            //
            //     }, function(){
            //         alert(知道了);
            //
            //     });
            // });

            // layer.confirm('确定删除记录？', {
            //     btn: ['是','否'] //按钮
            // }, function(){
            //     dealDeleteRecord(data);
            //
            // });
            //
            //
            // layer.msg('登录成功', {
            //     icon: 1,//提示的样式
            //     time: 2000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
            //     end:function(){
            //         alert(111)
            //     }
            // });


            // layer.msg('也可以这样', {
            //     btn: ['明白了', '知道了']
            //     ,yes: function(index, layero){
            //         layer.msg("按钮1回调,参数是:"+index)
            //     }
            //     ,btn2: function(index, layero){
            //         //按钮【按钮二】的回调
            //         layer.msg("按钮2回调,参数是:"+index)
            //         return false //开启该代码可禁止点击该按钮关闭
            //     }
            // });

            // layer.msg('也可以这样', {
            //     time: 10*1000, //20s后自动关闭
            //     btn: ['关闭']
            // });
            // layer.msg('的确很重要', {icon: 5,
            //     time: 10*1000,
            //     btn: ['关闭']
            // },function() {
            //     alert(知道了);
            // });

            // layer.msg('返回上一页', function() {
            //     history.go(-1);
            // });


            var id = $(data).parent().parent().children().first().text();
            var url = "${basePath}" + "/busInfo/" + id;
            alert(url);
            delRecord(url, function (resultData) {
                dealSuccessFunction(resultData, asyncRefreshDiv("#userTable"))
            });

        }




        function dealDeleteRecord(data) {
            //询问框

            // layer.confirm('您是如何看待前端开发？', {
            //     btn: ['重要','奇葩'] //按钮
            // }, function(){
            //     layer.msg('的确很重要', {icon: 1});
            // }, function(){
            //     layer.msg('也可以这样', {
            //         time: 20000, //20s后自动关闭
            //         btn: ['明白了', '知道了']
            //     });
            // });



            // layer.alert('偶吧深蓝style', {
            //     skin: 'layui-layer-lan'
            //     ,closeBtn: 0
            //     ,anim: 4 //动画类型
            // });
            var id = $(data).parent().parent().children().first().text();
            $.ajax({
                type: "DELETE",
                url: "${basePath}" + "/busInfo/" + id,
                dataType: "html",
                success: function(result){
                    // alert(111);
                    $("#userTable").load(location.href+" #userTable");
                    layer.msg('删除成功', {icon: 1});
                },
                error: function (result) {
                    alert("error:"+data.responseText);
                }

            });
        }

        //记录翻页
        function listRecord(data) {
            var userName = $("#queryUserName").text();
            var pageSize = "${listResult.pageSize}";
            var pageNo = $(data).text();
            var requestData = "?pageNo=" + pageNo + "&pageSize=" + pageSize;
            if(userName){
                requestData = requestData + "&userName=" + userName
            }
            // alert(requestData);
            $.ajax({
                type: "GET",
                url: "${basePath}" + "/busInfo/pageList" + requestData,
                dataType: "html",
                success: function(result){
                    $("#userTable").html(result);

                },
                error: function (result) {
                    alert("error:"+result.responseText);
                }

            });
        }

        //角色查询
        function queryRole(data) {
            var pageSize = "${listResult.pageSize}";
            var pageNo = 1;
            var requestData = "?pageNo=" + pageNo + "&pageSize=" + pageSize;
            var queryBusName = $("#queryBusName").val();
            if(queryBusName){
                requestData = requestData + "&busName=" + queryBusName
            }
            $.ajax({
                type: "GET",
                url: "${basePath}" + "/busInfo/pageList" + requestData,
                dataType: "html",
                success: function(result){
                    $("#allotPermission_table").html(result);
                },
                error: function (result) {
                    alert("error:"+result.responseText);
                }

            });
        }

        //修改记录
        function updateRecord(data) {
            var tdList = $(data).parent().parent().children();
            var id = tdList.eq(0).text();
            <#--var url = "${basePath}" + "/busInfo/";-->
            <#--var type = "PUT";-->
            <#--$("#updateBusInfo").click(function () {-->
                <#--alert(111);-->
                <#--commitModal(url, type, $('#form_addBusInfo').serialize());-->
                <#--$("#updateBusInfo").unbind("click");-->
            <#--});-->
            //设置id
            $.ajax({
                type: "GET",
                url: "${basePath}" + "/busInfo/" + id,
                dataType: "html",
                success: function (resultData) {
                    // alert(1111);
                    // $("#businessModal").load(location.href+" #businessModal");
                    $("#businessModal").html(resultData);
                    // alert("111");
                    $("#myModal2").modal("show");
                },
                error: function(resultData) {
                    alert("error:"+resultData.responseText);
                }
            });
        }

        //新增记录
        function insertRecord(data) {
            $("#myModalLabel").html("新增用户");
            $("#modalCancel").html("取消");
            $("#addRole").html("提交");
            $("#myModal").modal("show");
            $("#addRole").attr("onclick","");

            var url = "${basePath}" + "/busInfo/";
            var type = "POST";
            $("#addRole").click(function () {
                commitModal(url, type, $('#form_addUser').serialize());
                $('#addRole').unbind("click");
            });
        }

        //模态窗提交
        function commitModal(url, type, data) {
            $.ajax({
                type: type,
                url: url,
                data: data,
                dataType: "html",
                success: function (resultData) {
                    // alert(1111);
                    $("#userTable").load(location.href+" #userTable");
                    $('#myModal').modal('hide');
                },
                //调用执行后调用的函数
                // complete: function(XMLHttpRequest, textStatus){
                //     alert(XMLHttpRequest.responseText);
                //     alert(textStatus);
                // },
                error: function(resultData) {
                    alert("error:"+resultData.responseText);
                }
            });
        }
        //修改提交
        function updateBusInfo() {
            $.ajax({
                type: "PUT",
                url: "${basePath}" + "/busInfo/",
                data: $('#form_addBusInfo').serialize(),
                dataType: "html",
                success: function (resultData) {
                    $("#userTable").load(location.href+" #userTable");
                    $('#myModal2').modal('hide');
                },
                error: function(resultData) {
                    alert("error:"+resultData.responseText);
                }
            });
        }


    </script>
</head>
<body>
 <@_top.top 1/>
<div class="container" style="padding-bottom: 15px;min-height: 300px; padding-top: 60px;">
    <div class="row">
        <@_left.role 0/>
        <div id="userTable">
            <#include "business_table.ftl">
        </div>
    </div>
</div>

<div id="businessModal">
    <#include "business_modal.ftl">
    <form method="post" id="form1" enctype="multipart/form-data" accept="image/png,image/jpeg" action="https://api.weixin.qq.com/cgi-bin/media/uploadimg">
        <input type="file" name="buffer" class="upload_input" onchange="uploadFile(this);"  />
        <input type="hidden" name="access_token" value="" />
        <button id="uploadPic" type="submit">上传图片</button>
    </form>
</div>
<div class="modal fade" id="myModal" style="padding-top: 150px" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    新增商户
                </h4>
            </div>
            <div class="modal-body">
                <form id="form_addUser" class="form-horizontal" role="form">
                    <div class="form-group hidden">
                        <label for="firstname" class="col-sm-2 control-label">ID</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="userId" name="id" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">商户名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="busName" name="busName" placeholder="商户名称" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">商户地址</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="busAddress" value="" name="busAddress" placeholder="商户地址">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">登录名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="busLoginname" value="" name="busLoginname" placeholder="商户登录名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">登录密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="busLoginpassword" value="" name="busLoginpassword" placeholder="商户登录密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">发布进度</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="publishPlan" value="" name="publishPlan" placeholder="发布进度">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">发布版本</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="version" value="" name="version" placeholder="发布版本">
                        </div>
                    </div>
                    <#--<div class="form-group">-->
                        <#--<label for="lastname" class="col-sm-2 control-label">更新时间</label>-->
                        <#--<div class="col-sm-10">-->
                            <#--<input type="text" class="form-control" id="updateTime" value="" name="updateTime" placeholder="更新时间">-->
                        <#--</div>-->
                    <#--</div>-->


                </form>

            </div>

            <div class="modal-footer">

                <button type="button" id="modalCancel" onclick="function close() {
                            $('#myModal').modal('hide');
                        }" class="btn btn-default" data-dismiss="modal">取消
                </button>
                <button type="button" id="addRole" onclick="" class="btn btn-primary">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script src="/static/js/common/bootstrap/js/bootstrap.min.js"></script>

</body>

</html>